using System;
using System.Collections.Generic;
using System.Text;

using BuildingBasicDomain;

namespace MVCFramework.Models.Controllers
{
    [Serializable ]
    public class Controller : IController
    {
        public Id<IController> id;

        private static readonly LoggerAdapter log = new LoggerAdapter(typeof(Model));
        private IModel model;
        protected IModel Model
        {
            get { return model; }
            set { model = value; }
        }

        private IController inController;
        public  IController NextAdditionController
        {
            get { return inController; }
            set {
                log.Info("Controller  " + this.ToString() + "Assign NextInControoler  The " + value.ToString());
                inController = value; 
            }
        }

        private IController outController;
        public  IController NextRemovalController
        {
            get { return outController; }
            set 
            {
                log.Info("Controller  " + this.ToString() + "Assign NextOutController The " + value.ToString());
                outController = value; }
        }

        public Controller(IModel model)
        {
            this.model = model;
        }

        public virtual bool CheckAddition(IModelData _object)
        {
            DoCheckModelAddition(_object);
            return Model.AddObject(_object);
        }
        private bool DoCheckModelAddition(IModelData _object)
        {
            log.Info(this.GetType ().ToString() + "Check For Addition object " + _object.ToString());
            return true;
        }

        public virtual bool CheckRemoval(IModelData _object)
        {
            DoCheckModelRemoval(_object);
            return Model.RemoveObject(_object);
        }
        private bool DoCheckModelRemoval(IModelData _object)
        {
            log.Info(this.GetType ().ToString() + "Check For Removal object " + _object.ToString());
            return true;
        }

        #region IController IsEnabled Member

        bool isEnabled = true ;

        public bool IsEnabled
        {
            get
            {
                return isEnabled;
            }
            set
            {
                isEnabled = value;
            }
        }

        #endregion
    }
}
